package com.putong35.common.utils.io;

import android.content.Context;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Assets 工具类
 *
 * @Author: PV
 * @E-mail: pengveivei@sina.cn
 * @CreateDate: 2016/6/20 17:53
 * @Version: 1.0.0
 */
public class AssetsUtil {


    /**
     * 从asset的一级目录中读取文件中的string
     *
     * @param context
     * @param fileName
     * @return
     */
    public static String getStringFromAssets(Context context, String fileName) {
        try {
            InputStreamReader inputReader = new InputStreamReader(context.getResources().getAssets().open(fileName));
            BufferedReader bufReader = new BufferedReader(inputReader);
            String line = "";
            String result = "";
            while ((line = bufReader.readLine()) != null) {
                result += line;
            }
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }



}
